package com.mzm.remoting.invoker;

import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
import org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor;

import com.mzm.remoting.RemoteObjectLocator;


public class HttpInvokerLocator implements RemoteObjectLocator {

	@Override
	public Object getRemoteObject(String url, Class serviceClass) {
		HttpInvokerProxyFactoryBean fBean = new HttpInvokerProxyFactoryBean();
		fBean.setServiceUrl(url);
		fBean.setServiceInterface(serviceClass);
		fBean.setHttpInvokerRequestExecutor(new AuthenticationSimpleHttpInvokerRequestExecutor());
		try {
			fBean.afterPropertiesSet();
			Object obj = fBean
					.getObject();
			if(obj == null){
				throw new IllegalStateException("obj is null");
			}
			return obj;
		} catch (Exception e) {
			throw new IllegalStateException(e);
		}
	}

}
